home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / wdj0696.zip / ELLIOTT.ZIP / TRACEX.H < prev   
C/C++ Source or Header  |  1996-04-08  |  3KB  |  105 lines

  1. // ========================================================
  2. // tracex definition
  3. // Author: Keith Elliott  5/95
  4. //
  5. // tracex can be used to produce formatted trace entries
  6. // with indentations to indicate the call stack.  To use, 
  7. // simply instantiate a CTracex object on the stack at the 
  8. // beginning of those functions that you want to trace.  
  9. // Use the function name in the CTracex constructor.  The
  10. // CTracex object will automatically display a message to 
  11. // the Microsoft TRACE output at the current static 
  12. // indentation level.  It will then increase the static 
  13. // indentation level.  When the object is deleted as it 
  14. // goes out of scope, it will decrease the static 
  15. // indentation level and display a message that the exit 
  16. // was reached.
  17. //
  18. // The TRACEX macro has been provided to allow conditional 
  19. // compilation. In order to display a message at the 
  20. // current indentation level, use the TRACEXMSG, 
  21. // TRACEXMSGVAL, or TRACEXWATCH macros.
  22. //
  23. // Output example:
  24. // ---------------
  25. // CTestApp:InitInstance
  26. //   CQri::CQri
  27. //     CRepPage::CRepPage
  28. //     CRepPage::CRepPage exit
  29. //     CQrSheet::CQrSheet
  30. //     CQrSheet::CQrSheet exit
  31. //     CRepPage::SetDocTemplate
  32. //       CQrdvView::CQrdvView
  33. //       CQrdvView::CQrdvView exit
  34. //       CQrdvView::setQrSheet
  35. //       CQrdvView::setQrSheet exit
  36. //     CRepPage::SetDocTemplate exit
  37. //   CQri::CQri exit
  38. // CTestApp:InitInstance exit
  39. //
  40. // The macros will expand out to a semi-colon unless 
  41. // TRACEXON has been defined.  You can use these macros 
  42. // throughout the implementation of a class/module and can 
  43. // enable trace output for a module simply by defining 
  44. // TRACEXON before the header statement.  This provides an 
  45. // easier mechanism for placing a class/module into 
  46. // "trace debug" mode that having to repetatively 
  47. // comment/un-comment code.
  48. // =========================================================
  49.  
  50. #undef TRACEX
  51. #undef TRACEXMSG
  52. #undef TRACEXMSGVAL
  53. #undef TRACEXWATCH
  54.  
  55. #if defined (TRACEXON)
  56.   #define TRACEX(pString) CTracex tAutoTrace(pString);
  57.   #define TRACEXMSG(pString) {tAutoTrace.msg(pString);}
  58.   #define TRACEXMSGVAL(pString, pVal) \
  59.     {tAutoTrace.msg(pString, pVal);}
  60.   #define TRACEXWATCH(pVar) \
  61.     {tAutoTrace.msg( #pVar " == ", pVar);}
  62.  
  63. #else
  64.   #define TRACEX(pString) {;}
  65.   #define TRACEXMSG(pString) {;}
  66.   #define TRACEXMSGVAL(pString, pVal) {;}
  67.   #define TRACEXWATCH {;}
  68. #endif
  69.  
  70. #ifndef TRACEX_H
  71. #define TRACEX_H
  72.  
  73. #include <afx.h>
  74.  
  75. class CTracex : public CObject
  76.  {private:
  77.    CString mMsg;
  78.  
  79.   protected:
  80.    void traceIndent();
  81.     
  82.   public:
  83.    static int mIndent;
  84.    static BOOL mTracing;
  85.  
  86.    // When we have the keyword explicit, this single 
  87.    // argument constructor should be declared explicit to 
  88.    // prevent unintentional implicit type conversion.
  89.    // ----------------------------------------------------
  90.    CTracex(CString pMsg);
  91.    virtual ~CTracex();
  92.  
  93.    virtual void AssertValid() const;
  94.    void msg(const CString pMsg);
  95.    void msg(const CString pMsg, const int pInt);
  96.    void msg(const CString pMsg, const unsigned int pUint);
  97.    void msg(const CString pMsg, const long pLong);
  98.    void msg(const CString pMsg, const unsigned long pUlong);
  99.    void msg(const CString pMsg, const double pDouble);
  100.    void msg(const CString pMsg, const CString pString);
  101.    void msg(const CString pMsg, const CObject* pObject);
  102.  };
  103.  
  104. #endif //TRACEX_H
  105.